package 题目集.贪心.排序模拟;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;
//https://pintia.cn/problem-sets/1736591949399187456/exam/problems/1736591977547157514?type=7&page=0
public class 名人堂与代金券 {
    public static void main(String[] args) {
        Reader sc=new Reader();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        long res=0;
        TreeSet<Node> set=new TreeSet<>();
        for (int i = 0; i < n; i++) {
            Node node = new Node(sc.next(), sc.nextInt());
            if (node.score>=m){
                res+=50;
            }else if (node.score>=60){
                res+=20;
            }
            if (set.size()<k){
                set.add(node);
            }else {
                Node last = set.last();
                if (last.score > node.score){
                    continue;
                }else if (last.score< node.score){
                    set.pollLast();
                    set.add(node);
                }else {
                    set.add(node);
                }
            }
        }
        System.out.println(res);
        int rank=1;
        int pre=-1;
        int count=0;
        for (Node node : set) {
            count++;
            if (pre==node.score){
                System.out.println(rank+" "+node);
            }else {
                System.out.println(count+" "+node);
                pre=node.score;
                rank=count;
            }
        }
    }
    static class Node implements Comparable<Node>{
        String name;
        int score;

        public Node(String name, int score) {
            this.name = name;
            this.score = score;
        }

        @Override
        public int compareTo(Node other) {
            if (this.score==other.score){
                return this.name.compareTo(other.name);
            }
            return other.score-this.score;
        }

        @Override
        public String toString() {
            return name+" "+score;
        }
    }
    static class Reader {
        private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        private StringTokenizer tokenizer = new StringTokenizer("");

        private String innerNextLine() {
            try {
                return reader.readLine();
            } catch (IOException ex) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!tokenizer.hasMoreTokens()) {    //内存中没有
                String nextLine = innerNextLine();
                if (nextLine == null) {     //且没有下一行
                    return false;
                }
                tokenizer = new StringTokenizer(nextLine);  //读入一行
            }
            return true;
        }

        public String nextLine() {
            tokenizer = new StringTokenizer("");    //清空内存中的字符
            return innerNextLine();
        }

        public String next() {
            hasNext();
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }

}

